package com.learning.code.multithread.keyword.synchronize.method.memberVaribles;

public class HasMemberVariablesAndSynchronizedMethod {

    // 定义一个类内的变量num，即成员变量
    private int num =0;
    public synchronized void changeNumByName(String name){
        try {
            if(name.equals("xiaoming2")){
                num = 100;
                System.out.println("xiaoming2 set over");
                Thread.sleep(2000);

            }else {
                num = 200;
                System.out.println("others2 set over");
            }
            System.out.println(name + "'num is " + num);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
